/*
 * Licensed to the anubis
 *
 * Copyright (c) 2023 .
 * All rights reserved.
 * 项目名称：anubis-demo-web
 * 项目描述：基于spring5的spring-mvc新特性
 * 版权说明：本软件属XXX有限公司所有，在未获得XXX有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.anubis.demo.web.controller;

import com.anubis.demo.pojo.dto.UserRegistration;
import com.anubis.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/registration")
public class RegistrationController {

    @Autowired
    private UserService userService;

    /**
     * ...
     */
    @ModelAttribute("user")
    public UserRegistration userRegistrationDto() {
        return new UserRegistration();
    }

    /**
     * ...
     */
    @GetMapping
    public String showRegistrationForm() {
        return "registration";
    }

    /**
     * ...
     */
    @PostMapping
    public String registerUser(@ModelAttribute("user") UserRegistration userRegistration) {
        userService.save(userRegistration);
        return "redirect:/registration?success";
    }

}
